// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import DataMgr from "./common/DataMgr";

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    _resurrection_view: fgui.GComponent;

    _integral_view: fgui.GLabel;

    _progress_view: fgui.GProgressBar;

    // LIFE-CYCLE CALLBACKS:
    // use this for initialization

    onLoad() {
        fgui.addLoadHandler();

        fgui.GRoot.create();

        fgui.UIPackage.loadPackage("UI/IMGame", this.onUILoaded.bind(this));
    }

    onUILoaded() {
        fgui.UIPackage.addPackage("UI/IMGame");

        this._resurrection_view = fgui.UIPackage.createObject("IMGame", "ResurrectionPanel").asCom;
        this._resurrection_view.makeFullScreen();

        this._progress_view = this._resurrection_view.getChild("n25").asProgress;

        this.schedule(this.__playProgress, 0.01);

        //积分
        this._resurrection_view.getChild("n12").onClick(this.onResurrectionClick, this);
        this._resurrection_view.getChild("n15").onClick(this.onGiveUpClick, this);

        fgui.GRoot.inst.addChild(this._resurrection_view);
        // this.loadRootUI();

    }

    private __playProgress(): void {
        // var obj: fgui.GComponent = this._progress_view;
        // var cnt: number = obj.numChildren;
        // for (var i: number = 0; i < cnt; i++) {
        var child: fgui.GProgressBar = this._progress_view;
        if (child != null) {
            child.value += 1;
            if(child.value===child.max){
                //到最大值了
                

            }
            // if (child.value > child.max)
            //     child.value = 0;
        }
        // }
    }


    loadRootUI() {
        //积分
        this._resurrection_view.getChild("n12").onClick(this.onResurrectionClick, this);
        this._resurrection_view.getChild("n15").onClick(this.onGiveUpClick, this);

        fgui.GRoot.inst.addChild(this._resurrection_view);

        // this._progress_view.setProp();
    }


    //点击复活按钮
    onResurrectionClick() {
        // console.log("onResurrectionClick");
        cc.director.loadScene('game');
        // _resurrection_view.removeFromParent();
    }

    //点击放弃按钮
    onGiveUpClick() {
        cc.sys.localStorage.setItem('level', 1);
        DataMgr.reset();
        cc.director.loadScene('start');
        // console.log("onGiveUpClick");
    }

    start() {

    }

}
